package ru.ifmo.metopt;

import ru.ifmo.metopt.abstracts.AbstractFunction;
import ru.ifmo.metopt.abstracts.Function;

/**
 * @author avhaliullin
 */
public class InternalPointExtension extends AbstractFunction {

    private final Function function;
    private final Function[] restrictions;
    private double p = 1;

    public InternalPointExtension(Function function, Function... restrictions) {
        this.function = function;
        this.restrictions = restrictions;
    }

    @Override
    protected double safeF(double... args) {
        double _p = 1 / p;
        double res = function.f(args);
        for (Function restriction : restrictions) {
            res += _p / restriction.f(args);
        }
        return res;
    }

    @Override
    public int dimensionality() {
        return function.dimensionality();
    }

    public double getP() {
        return p;
    }

    public void setP(double p) {
        this.p = p;
    }
}
